<!-- 面试查询详情 -->

<script>
import bus from "@/eventBus";
import InterviewDetailLeftNav from "@/components/detailCommons/interviewDetailLeftNav";
import InterviewDetailCandidate from "@/components/detailCommons/interviewDetailCandidate";
import InterviewDetailDemand from "@/components/DemandDetail";
import InterviewDetailChat from "@/components/detailCommons/interviewDetailChat";
import InterviewDetailVia from "@/components/detailCommons/interviewDetailVia";
import InterviewCourse from "@/components/interviewCourses/interviewCourse";
import InterviewDetailNotGo from "@/components/detailCommons/interviewDetailNotGo";
import { getByteLen } from "@/utils/strLength";
import { decCourses } from "@/decs/dec_interviewCourse";
import { dec_demandDetail } from "@/decs/dec_interviewDemandDetail";
import InterviewTimeCourse from "@/components/interviewCourses/InterviewTimeCourse";
function fetchInquiriesDetailInfo(store, opts) {
  return store.dispatch("FETCH_INQUIRIES_DETAIL", opts);
}
export default {
  components: {
    InterviewDetailCandidate,
    InterviewDetailDemand,
    InterviewDetailLeftNav,
    InterviewDetailChat,
    InterviewDetailNotGo,
    InterviewDetailVia,
    InterviewCourse,
    InterviewTimeCourse,
  },
  data() {
    return {
      isPassed: false,
      isPass: false,
      userInfo: {
        name: "",
        ex: "",
        fileUrl: "",
        zz: "",
      },
      navs: [
        {
          lable: "简历进展概况",
          id: "1",
          val: "fill-in",
          isActive: true,
        },
        {
          lable: "候选人信息",
          id: "2",
          val: "candidate",
          isActive: false,
        },
        {
          lable: "需求详情",
          id: "3",
          val: "demand",
          isActive: false,
        },
        {
          lable: "面试时间进程",
          id: "4",
          val: "interview-time",
          isActive: false,
        },
      ],
      notGoData: {
        feed_back: "",
        text: "面试不通过",
        iconTxt: "icon-ku-mian",
        iconColor: "#cbc9c6",
      },
      viaFeedBackData: {
        admitmobile: "", // 入场联系电话
        admitaddress: "", // 入场地点
        admitlinkman: "", // 入场联系人
        admittime: "", // 入场时间
        mobile: "", // 面试官电话
        sur_name: "", // 面试官名字
        feed_back: "", // 面试反馈
        state: "", // 面试状态
      },
      courseInfos: [], // 简历历程
      chartData: {
        GYInfo: {},
        DDInfo: {},
      },
      nominateInfo: {
        name: "",
        phone: "",
        email: "",
        companyName: "",
      },
      candidateData: {
        name: "",
        record: "",
        handsOn: "",
        isInJob: "",
        comeTime: "",
        phone: "",
        desc: "",
      },
      demandData: {
        jobName: "",
        jobType: "",
        moenyType: "",
        reportsTo: "",
        quantity: "",
        workingDeadline: "",
        workYears: "",
        jobAddress: "",
        budget: "",
        supplier: "",
        inJobTime: "",
        publishTime: "",
        jobDesc: "",
        jobAsk: "",
        needsCode: "",
        pathO: "",
        pathT: "",
        pathS: "",
        needsNumber: "",
      },
    };
  },
  created() {
    const id = this.$route.params.id;
    const stus = this.$route.query.stus || {};
    this.getStateFormatEle(stus);
    this.fetchDetailData(id);
  },
  mounted() {
    bus.$on("select-tab", this.selectTabItem);
  },
  methods: {
    // * 根据数据状态初始化页面
    getStateFormatEle(state) {
      switch (state) {
        case 2:
          // * 已通过
          this.isPassed = false;
          this.isPass = true;
          console.log("进来这里勒嘛？");
          break;
        case 3:
          // * 未通过
          this.isPassed = true;
          this.isPass = false;
          break;
        case 5:
          // * 面试待定
          this.notGoData.text = "面试待定";
          this.notGoData.iconTxt = "icon-kulian";
          this.notGoData.iconColor = "#fea44d";
          this.isPassed = true;
          this.isPass = false;
          break;
        default:
          break;
      }
    },
    // * 获取详情数据
    async fetchDetailData(needsId) {
      if (!needsId) return;
      await fetchInquiriesDetailInfo(this.$store, { needsId });
      let { state, data } = this.$store.getters.getInquiriesDetailInfo;
      if (state === "0000") {
        const {
          referrerInfo,
          interviewFeedback,
          cvdbInfo,
          needsDetails,
          interviewArrange,
          depts,
          cvdbCourse,
        } = data || {};
        // 推荐人信息
        if (referrerInfo) {
          let strLength = getByteLen(referrerInfo.supplierName);
          let tempStr = "";
          if (strLength > 16) {
            tempStr = referrerInfo.supplierName.substr(0, 12) + "...";
          } else {
            tempStr = referrerInfo.supplierName;
          }
          this.nominateInfo = {
            name: referrerInfo.uploader_name,
            phone: referrerInfo.uploader_mobile,
            email: referrerInfo.uploader_email,
            companyName: tempStr,
            tempCompayName: referrerInfo.supplierName,
          };
        }

        // * 面试反馈信息
        if (interviewFeedback) {
          let { state } = interviewFeedback || {};
          if (state === 1) {
            this.isPassed = false;
            this.isPass = false;
          } else if (state === 2) {
            // 入场反馈
            this.viaFeedBackData = {
              admitmobile: interviewFeedback.admitmobile,
              admitaddress: interviewFeedback.admitaddress,
              admitlinkman: interviewFeedback.admitlinkman,
              admittime: interviewFeedback.admittime,
              mobile: interviewFeedback.mobile,
              sur_name: interviewFeedback.sur_name,
              feed_back: interviewFeedback.feed_back,
              state: interviewFeedback.state,
            };
          }
          this.notGoData.feed_back = interviewFeedback.feed_back;
        }

        // * 候选人信息
        if (cvdbInfo) {
          this.candidateData = {
            name: cvdbInfo.surname,
            record: cvdbInfo.education_code,
            handsOn: cvdbInfo.work_experience,
            isInJob: cvdbInfo.current_status_code,
            comeTime: cvdbInfo.post_time,
            phone: cvdbInfo.telephone,
            desc: cvdbInfo.reason,
          };
        }

        // 需求详情
        if (needsDetails) {
          this.demandData = dec_demandDetail(needsDetails, "", "", "", depts);
        }

        // 候选人信息
        this.userInfo.name = this.candidateData.name;
        this.userInfo.ex = this.demandData.postCode;
        this.userInfo.positionName = needsDetails.positionName;
        this.userInfo.zz = cvdbInfo.file_url;
        this.userInfo.cvdbId = cvdbInfo.id; // 文件路径ID
        this.userInfo.fileName = cvdbInfo.fileName;
        if (interviewArrange) {
          let tempGYInfo = {
            chatTime: interviewArrange.SUpdate_date,
            interTime: interviewArrange.SInterview_time,
            desc: interviewArrange.SBack_remark,
          };
          let tempStr = "";
          let tempStrs = [];
          if (
            interviewArrange.DInterview_time &&
            interviewArrange.DInterview_time.indexOf(",") != -1
          ) {
            tempStrs = interviewArrange.DInterview_time.split(",");
          } else {
            tempStr = interviewArrange.DInterview_time;
          }
          let tempDDInfo = {
            chatTime: interviewArrange.DUpdate_date, // 聊天更新时间
            interTime: tempStr || tempStrs[0], // 面试时间
            interTime1: tempStrs[1] || "", // 面试时间
            interTime2: tempStrs[2] || "", // 面试时间
            desc: interviewArrange.DRemarks, // 备注
            format: interviewArrange.DInterview_format, // 面试形式
            addr: interviewArrange.DAddress, // 面试地点
            interviewName: interviewArrange.DInterviewName, // 面试官
            interviewPhone: interviewArrange.DInterviewMobile, // 面试官电话
          };
          this.chartData = {
            GYInfo: tempGYInfo,
            DDInfo: tempDDInfo,
          };
        }
        // 简历进展历程
        this.courseInfos = decCourses(cvdbCourse);
      }
    },
    // * 切换左侧tab选项
    selectTabItem(type) {
      _j("[mode-type=" + type + "]")
        .siblings(".module-box")
        .removeClass("is-active-tab");
      _j("[mode-type=" + type + "]").addClass("is-active-tab");
    },
  },
  beforeDestroy() {
    bus.$off("select-tab", this.selectTabItem);
  },
};
</script>

<template>
  <ul
    class="interview-common-detail resume-container"
    style="position: relative"
  >
    <backButton :backPath="'/selectint'" />
    <li class="resume-detail-left">
      <InterviewDetailLeftNav
        :userInfo="userInfo"
        :navs="navs"
        :nominateInfo="nominateInfo"
      ></InterviewDetailLeftNav>
    </li>
    <li class="resume-detail-right">
      <div v-if="isPass">
        <InterviewDetailVia :viaData="viaFeedBackData"></InterviewDetailVia>
      </div>
      <div v-if="isPassed">
        <InterviewDetailNotGo :notGoData="notGoData"></InterviewDetailNotGo>
      </div>
      <div class="module-box is-active-tab" v-bind:mode-type="'fill-in'">
        <interview-course :course-infos="courseInfos"></interview-course>
      </div>
      <div class="module-box" v-bind:mode-type="'interview-time'">
        <interview-time-course :course-infos="courseInfos"></interview-time-course>
      </div>
      <div class="module-box" v-bind:mode-type="'candidate'">
        <interview-detail-candidate
          :candidateInfo="candidateData"
        ></interview-detail-candidate>
      </div>
      <div class="module-box" v-bind:mode-type="'demand'">
        <interview-detail-demand
          :textDatas="demandData"
          :isShowInterviewBox="false"
        ></interview-detail-demand>
      </div>
    </li>
  </ul>
</template>

<style lang="scss">
@import "~@/assets/scss/mixins.scss";
@include Interview-detail;

// .detail-container {
//   padding-bottom: 20px;
//   margin-bottom: 40px;
//   width: 100%;
//   background: none;
//   .aside-box {
//     overflow: hidden;
//     float: left\0;
//   }
//   .main-box {
//     padding-top: 0px;
//     padding-bottom: 0px;
//     padding-right: 0px;
//     float: left\0;
//   }
// }

// .title-box {
//   width: 100%;
//   height: 44px;
//   line-height: 44px;
//   background-color: #f8f8f8;
//   color: #636363;
//   padding-left: 20px;
//   text-align: left;
//   box-sizing: border-box;
// }

// .sub-module-title {
//   height: 48px;
//   border-bottom: 2px solid #f1f1f1;
//   line-height: 48px;
//   text-align: left;
//   color: #636363;
//   font-weight: 600;
//   font-size: 14px;
// }

// .module-box {
//   display: none;
// }

// .module-box.is-active-tab {
//   display: block;
// }
</style>
